package com.example.mybatisplus.holder;

/**
 * spd 用户帮助类
 *
 * @author Andy
 * @time 2022/3/14 17:33
 */
public class SpdUserIdHolder {
    private static ThreadLocal<Integer> localUserId = new ThreadLocal<>();

    /**
     *
     * 获取当前用户ID
     *
     * @return 用户ID
     */
    public static Integer getCurrentUserId(){
        return localUserId.get();
    }

    /**
     * 设置用户ID
     *
     * @param userId 用户ID
     */
    public static void set(Integer userId){
        localUserId.set(userId);
    }

    /**
     * 清空用户信息
     */
    public static void clear(){
        localUserId.remove();
    }
}
